import { defineStore } from "pinia";
import { UserState, HandlePurview } from "@/stores/interface";
import piniaPersistConfig from "@/config/piniaPersist";
import { WHITE_MENU_LIST } from "@/config/index";
export const useUserStore = defineStore({
  id: "user",
  state: (): UserState => ({
    token: "",
    userInfo: { userName: "" },
    menuList: [],
    functionList: [],
    handlePurviewData: {}
  }),
  getters: {},
  actions: {
    // Set Token
    setToken(token: string) {
      this.token = token;
    },
    // Set UserInfo
    setUserInfo(userInfo: UserState["userInfo"]) {
      this.userInfo = userInfo;
    },
    // Set MenuList
    setMenuList(menuList: string[]) {
      this.menuList = [...menuList, ...WHITE_MENU_LIST];
    },
    // Set FunctionList
    setFunctionList(functionList: string[]) {
      this.functionList = functionList;
    },
    // Set HandlePurviewList
    setHandlePurviewData(handlePurviewData: HandlePurview) {
      this.handlePurviewData = handlePurviewData;
    }
  },
  persist: piniaPersistConfig("user")
});
